/*
 * OnlinePayProvider.java
 * business
 *
 * Created by chentao on 2017/5/9.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.recyclerview.provider;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.yidiandao.business.R;
import com.yidiandao.business.data.response.QueryMultiPayWaysResultResponse;
import com.yidiandao.business.ui.main.shoppingcart.cashier.CashierActivity;
import com.yidiandao.business.utils.UIUtils;

import me.drakeet.multitype.ItemViewProvider;

/**
 * 多订单  去 在线支付的Provider
 * <p>
 * Created by ChenTao(chentao7v@gmail.com) on 2017/5/9 0009 10:29
 */
public class ToOnlinePayProvider extends ItemViewProvider<QueryMultiPayWaysResultResponse.OnlinePayState, ToOnlinePayProvider.ViewHolder> {

    private Activity mActivity;

    public ToOnlinePayProvider(Activity activity) {
        mActivity = activity;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_to_online_pay, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final QueryMultiPayWaysResultResponse.OnlinePayState state) {
        holder.btnOnlinePay.setText(UIUtils.getString(R.string.go_to_online_pay, state.getMoney()));

        holder.btnOnlinePay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toCashierActivity(state.getUrl(), state.getOrderPayId(), state.getMoney());
            }
        });
    }

    private void toCashierActivity(String url, String orderPayId, String totalOnlinePay) {
        CashierActivity.actionStart(mActivity, url, orderPayId, totalOnlinePay, false);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private Button btnOnlinePay;

        public ViewHolder(View itemView) {
            super(itemView);
            btnOnlinePay = (Button) itemView.findViewById(R.id.btn_online_pay);
        }
    }
}
